<form [formGroup]="objectForm" (ngSubmit)="save()" autocomplete="off">
  <div class="modal-header">
    <h4 class="modal-title" id="modal-basic-title">{{getTitle()}}</h4>
    @if (object?.id) {
      <span class="badge bg-primary text-primary-text-contrast ms-2">ID: {{object.id}}</span>
    }
    <button type="button" [disabled]="!closeEnabled" class="btn-close" aria-label="Close" (click)="cancel()">
    </button>
  </div>
  <div class="modal-body">
    <div class="row">
      <div class="col">
        <pngx-input-text i18n-title title="Name" formControlName="name" [error]="error?.name" autocomplete="off"></pngx-input-text>
        <pngx-input-text i18n-title title="IMAP Server" formControlName="imap_server" [error]="error?.imap_server"></pngx-input-text>
        <pngx-input-text i18n-title title="IMAP Port" formControlName="imap_port" [error]="error?.imap_port"></pngx-input-text>
        <pngx-input-select i18n-title title="IMAP Security" [items]="imapSecurityOptions" formControlName="imap_security"></pngx-input-select>
      </div>
      <div class="col">
        <pngx-input-text i18n-title title="Username" formControlName="username" [error]="error?.username"></pngx-input-text>
        <pngx-input-password i18n-title title="Password" formControlName="password" [error]="error?.password"></pngx-input-password>
        <pngx-input-check i18n-title title="Password is token" i18n-hint hint="Check if the password above is a token used for authentication" formControlName="is_token" [error]="error?.is_token"></pngx-input-check>
        <pngx-input-text i18n-title title="Character Set" formControlName="character_set" [error]="error?.character_set"></pngx-input-text>
      </div>
    </div>
  </div>
  <div class="modal-footer">
    <div class="m-0 me-2">
      @if (testResult) {
        <ngb-alert #testResultAlert [type]="testResult" class="mb-0 py-2" (closed)="testResult = null">{{testResultMessage}}</ngb-alert>
      }
    </div>
    <button type="button" class="btn btn-outline-primary" (click)="test()" [disabled]="networkActive || testActive">
      @if (testActive) {
        <div class="spinner-border spinner-border-sm me-2" role="status"></div>
        <span class="visually-hidden mr-1" i18n>Loading...</span>
      }
      <ng-container i18n>Test</ng-container>
    </button>
    <button type="button" class="btn btn-outline-secondary" (click)="cancel()" i18n [disabled]="networkActive">Cancel</button>
    <button type="submit" class="btn btn-primary" i18n [disabled]="networkActive">Save</button>
  </div>
</form>
